//
//  Product.swift
//  lottery
//
//  Created by admin on 16/2/4.
//  Copyright © 2016年 jin. All rights reserved.
//

import UIKit

class Product: NSObject {
    var title:String!
    var id:String!
    var url:String!
    var icon:String!
    var customUrl:String!
    init(title:String,id:String,url:String,icon:String,customUrl:String) {
        self.title = title
        self.id = id
        self.url = url
        self.icon = icon
        self.customUrl = customUrl
    }
    override init() {
        
    }
    convenience init(dic:[String : AnyObject]) {
        self.init()
        self.setValuesForKeysWithDictionary(dic)
    }
    class func instanceOfFile()->[Product]
    {
        let path = NSBundle.mainBundle().pathForResource("products.json", ofType: nil)
        let data = NSData(contentsOfFile: path!)
        let arr:NSArray = try! NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as! NSArray
        var products:[Product] = []
        for var i = 0;i < arr.count;i++
        {
            products.append(Product(dic: arr[i] as! [String : AnyObject]))
        }
        return products
    }
    
}
